<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <div id="app">
        <ul>
            <!-- 数组循环 -->
            <li v-for="(user,index) in users" :key="user.name">
                当前索引{{user.name}} ==> {{user.sex==1?"男":"女"}} ==> {{user.sex | getSex}} ==> {{user.sex | getSex1}} <br>
            </li>
        </ul>

    </div>

</body>
<script src="../node_modules/vue/dist/vue.js"></script>

<script>
    //全局过滤器
    Vue.filter("getSex1", function (val) {
        if (val == 1) {
            return "男"
        } else {
            return "女"
        }
    })

    let vm = new Vue({
        el: "#app",
        data: {
            users: [
                { name: "李长锐", sex: "1", age: 19 },
                { name: "李锐", sex: "1", age: 20 },
                { name: "李长", sex: "0", age: 21 },
                { name: "长锐", sex: "1", age: 22 }
            ]
        },
        //过滤器
        filters: {
            //局部过滤器
            getSex(val) {
                if (val == 1) {
                    return "男"
                } else {
                    return "女"
                }

            }

        }

    });

</script>

</html>